import JSEncrypt from "jsencrypt/bin/jsencrypt.min";



const crypt = new JSEncrypt();
// 公钥，由后端接口返回，这里写死作为测试
const publicKey =
  "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCHQh8qVJF1nJ0A-iL_ksa9kcF9-GmQ8BidUg5p78jjeuSBDaR-vc6jM9SxPmfWPfEOtXrIQj0y3_isEv1Z8PeSO1pLt2pP5gSgp3OATChDz--T46dkQpkAIw3bsWkS6RAgEssRvr6xWsD112wMDI2z6K8XbCPbCPDA3tRiTdKwtQIDAQAB";
crypt.setPublicKey(publicKey);
let privateKey =
  "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAIdCHypUkXWcnQD6Iv-Sxr2RwX34aZDwGJ1SDmnvyON65IENpH69zqMz1LE-Z9Y98Q61eshCPTLf-KwS_Vnw95I7Wku3ak_mBKCnc4BMKEPP75Pjp2RCmQAjDduxaRLpECASyxG-vrFawPXXbAwMjbPorxdsI9sI8MDe1GJN0rC1AgMBAAECgYBUoUy6wbtZ6apbKCep3f64MnDtDveOlovwM52NL1l07Dn5fb3FB6I5f36_gBqcdJlV6LtwffGo2XbQw_j9w8ZDL4tQ4PMY_2u_2n-WKsqwit5CuQU49DckQFODdHvsaT7CwVvAcrkgW4s3gMVVU79nO5oHWys2CX4PlKky5Af86QJBANisB2g06NNcPAUSoYBW3k-W2XupakxdJ2DTQwR_B2ODvfMVtoTYC0t_nJkFL8ubXE3NTnRz3UT5Zu83wdbD0PsCQQCfzxb_AuWtbeacnQYJh-IaCA8Nmz_8mdz7d1ErE5FaAKCz7SHmbCEnl9Uaz8Ejz_MfwynWuI_FqegVltxwpbYPAkAUiZnaIsm-3wtBX9a3F4TS_nV250QQIPROlTfRAUluAVrL4879II1RhrMNPhSdtAg3x7IcD691jj5Xhm11MfJpAkAoX5xSrrux1fsWBAGbdM3lf7W13UwMGB8hFKLX_CiTkWcILdeLrDOwGgbHsEb-MjIdCyRNz_DaojM1CRkGCId3AkBDkNoGHdXyhGucMF2R5IAk4MmxWQS_JWpcz_-nvPfMIc_di8EIr9z_5CFvNLl9PbjY2r5HGeNhr2WTTC5Mn6iz";

//加密方法

function RSAencrypt(pas){
//实例化jsEncrypt对象
let jse = new JSEncrypt();
//设置公钥
jse.setPublicKey(publicKey);
console.log('加密：'+jse.encrypt(pas))
return jse.encrypt(pas);
}


//解密方法
function RSAdecrypt(pas){
let jse = new JSEncrypt();
// 私钥
jse.setPrivateKey(privateKey)
console.log('解密：'+jse.decrypt(pas))
return jse.decrypt(pas);
}

export { RSAdecrypt, RSAencrypt};